package leetcode.秋招.字节跳动.字节研发在线编程;

import org.junit.Test;

/**
 * @author ：zsy
 * @date ：Created 2021/7/25 12:30
 * @description：
 */
public class NC78反转链表 {
    @Test
    public void test() {
        Solution solution = new Solution();
    }


    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

    public class Solution {
        public ListNode ReverseList(ListNode head) {
            //头插法
            ListNode curHead = new ListNode(-1);
            ListNode temp = head;
            while (temp != null) {
                ListNode next = temp.next;
                temp.next = curHead.next;
                curHead.next = temp;
                temp = next;
            }
            return curHead.next;
        }

    }
}
